﻿
/**
 * implementation of DFS: let fringe be a last-in-first-out (LIFO) stack
 */
public class DFS : IGenericSearch
{
    /** fringe = LIFO stack */
    private System.Collections.Generic.Stack<Node> mFringe;

    /**
     * Constructor calls super constructor
     */
    public DFS(string fn) : base(fn)
    {
        mFringe = new System.Collections.Generic.Stack<Node>();
    }

    /**
     * insert a node to the fringe 
     */
    public override void generic_insertToFringe(Node n)
    {
        mFringe.Push(n);
    }

    /**
     * test if fringy is empty
     */
    public override bool generic_isFringeEmpty()
    {
        return (mFringe.Count == 0);
    }

    /**
     * remove first element of fringe 
     */
    public override Node generic_removeFirst()
    {
        return mFringe.Pop();
    }

    /**
     * insert nodes into fringe 
     */
    public override void generic_insertAll(System.Collections.Generic.List<Node> nodes)
    {
        foreach (Node n in nodes) { mFringe.Push(n); }
    }
    

} // class DFS